package com.xiaobing.auth.controller;


import com.xiaobing.auth.service.login.SysLoginService;
import com.xiaobing.common.povo.LoginUser;
import com.xiaobing.common.res.Result;
import com.xiaobing.common.token.TokenService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * token 控制
 */
@RestController
@RequestMapping("/auth")
public class LoginController {

    @Resource
    private TokenService tokenService;

    @Resource
    private SysLoginService sysLoginService;

    @PostMapping("/login")
    public Result<?> login(@RequestBody LoginUser form) {
        // 用户登录
        LoginUser userInfo = sysLoginService.login(form.getUserName(), form.getPassword());
        // 获取登录token
        return Result.success(tokenService.createToken(userInfo));
    }

}
